package com.mlog.njyjy.ndop.msg.relay.service.impl;

import com.mlog.njyjy.ndop.msg.common.domain.MessageRecord;
import com.mlog.njyjy.ndop.msg.persistence.dao.MessageRecordRepository;
import com.mlog.njyjy.ndop.msg.relay.service.StatsService;
import com.mlog.njyjy.ndop.share.sql.support.SqlTableUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author zyz
 * @version v1.0, 2020/8/7
 */
@Service
public class StatsServiceImpl implements StatsService {

    @Autowired
    private MessageRecordRepository messageRecordRepository;

    String sql = "select * from " + SqlTableUtil.getTblName(MessageRecord.class) + " where msg_key = ?";

    @Override
    public List<MessageRecord> statsByType(String type) {

        return messageRecordRepository.find(sql, type);
    }

    @Override
    public List<MessageRecord> statsByPID(String pid) {
        return messageRecordRepository.find(sql, pid);
    }

    @Override
    public List<MessageRecord> statsByErrCode(String errCode) {
        return messageRecordRepository.find(sql, "error" + errCode);
    }

    @Override
    public List<MessageRecord> statsByErrCodeAndType(String errCode, String type) {
        return messageRecordRepository.find(sql, "error" + errCode + type);
    }

    @Override
    public List<MessageRecord> statsByErrCodeAndPID(String errCode, String pid) {
        return messageRecordRepository.find(sql, "error" + errCode + pid);
    }
}
